﻿unit MainServerFrm;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ExtCtrls, Vcl.Buttons, Vcl.ComCtrls,
  Vcl.Samples.Spin, MemBuffer, ContextFactory, Protocol, TCPService, MonitorFrm,
  DBService, ADOConPool, DBConnect;

type
  TFrmMainServer = class(TForm)
    Panel1: TPanel;
    pal: TPanel;
    spStart: TSpeedButton;
    spStop: TSpeedButton;
    sBarMain: TStatusBar;
    pageServer: TPageControl;
    tabSysParameters: TTabSheet;
    tablog: TTabSheet;
    tabserver: TTabSheet;
    GroupBox1: TGroupBox;
    LabelGatePort: TLabel;
    Bevel1: TBevel;
    LabelServerIPaddr: TLabel;
    Label4: TLabel;
    Label1: TLabel;
    Label2: TLabel;
    crsLocalPort: TEdit;
    crsThread: TSpinEdit;
    spHeatbeTime: TSpinEdit;
    chkLog: TCheckBox;
    chkDeadSocket: TCheckBox;
    crsMaxConn: TSpinEdit;
    crsBuffer: TSpinEdit;
    lvLog: TListView;
    Timer1: TTimer;
    FServer: TDBService;
    DBConfig: TDBConfig;
    DBConn: TDBConnection;
    procedure spStartClick(Sender: TObject);
    procedure spStopClick(Sender: TObject);
    procedure FServerCloseSocket(FChannel: TObject);
    procedure FServerOpenSocket(FChannel: TObject);
    procedure FServerRecvSocket(FChannel: TObject; FBuffer: TIBuffer;
      dwIoSize: Cardinal);
    procedure FServerSendSocket(FChannel: TObject; FBuffer: TIBuffer;
      dwIoSize: Cardinal);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FrmMainServer: TFrmMainServer;

implementation

{$R *.dfm}

procedure TFrmMainServer.spStartClick(Sender: TObject);
begin
  FServer.Port := StrToInt(crsLocalPort.text);
  FServer.MaxMemPool := crsBuffer.Value;
  FServer.MaxClientPool := crsMaxConn.Value;
  FServer.MaxWorkPool := crsThread.Value;
  FServer.KeepAlive := Self.chkDeadSocket.Checked;
  spStart.Enabled := not FServer.StartService;
  spStop.Enabled := not spStart.Enabled;
  sBarMain.Panels[0].Text := '服务启动';
end;

procedure TFrmMainServer.spStopClick(Sender: TObject);
begin
  FServer.StopService;
  spStart.Enabled:= True;
  spStop.Enabled := not spStart.Enabled;
  sBarMain.Panels[0].Text := '服务停止';
end;

procedure TFrmMainServer.FServerOpenSocket(FChannel: TObject);
begin
  //
end;

procedure TFrmMainServer.FormCreate(Sender: TObject);
begin
  FrmMonitor := TFrmMonitor.Create(tabServer, FServer._TCPEngine, FServer._TCPListener);
  FrmMonitor.Show;
  FrmMonitor.ManualDock(tabServer, nil, alClient);
end;

procedure TFrmMainServer.FServerCloseSocket(FChannel: TObject);
begin
  //
end;

procedure TFrmMainServer.FServerRecvSocket(FChannel: TObject; FBuffer: TIBuffer; dwIoSize: Cardinal);
var
  FClientContext: TIClientContext;
begin
  if FChannel is TIClientContext then
  begin
    FClientContext := FChannel as TIClientContext;
    FClientContext.ProcessDataStream(FBuffer);
  end;
end;

procedure TFrmMainServer.FServerSendSocket(FChannel: TObject; FBuffer: TIBuffer;
  dwIoSize: Cardinal);
var
  FClientContext: TIClientContext;
begin
  if FChannel is TIClientContext then
  begin
    FClientContext := FChannel as TIClientContext;
  end;
end;

end.
